package com.cjy.common.utils.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.TextFieldTag;

import com.cjy.common.utils.ApplicationUtils;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * input tag :<xx:input id="..." authId="...authId.."/> the authId is required
 * 
 * @author jay.zhoujingjie Date: 13-12-14 Time: 上午11:03
 */

public class InputTag extends TextFieldTag {
	// 权限key
	private String authKey;
	private String placeholder;

	public String getPlaceholder() {
		return placeholder;
	}

	public void setPlaceholder(String placeholder) {
		this.placeholder = placeholder;
	}

	public String getAuthKey() {
		return authKey;
	}

	public void setAuthKey(String authKey) {
		this.authKey = authKey;
	}

	@Override
	public Component getBean(ValueStack stack, HttpServletRequest req,
			HttpServletResponse res) {
		return new InputTagBean(stack, req, res);
	}

	@Override
	protected void populateParams() {
		if (disabled != null) {
			if ("disabled".equals(disabled)) {
				disabled = "true";
			}
		}
		if (id == null) {
			id = "";
		}
		super.populateParams();
		InputTagBean input = (InputTagBean) component;
		input.setVisible(ApplicationUtils.isAllowAsThisAction(authKey));
		input.setPlaceholder(placeholder);

	}
}
